import {RSAUtil} from "@/utils/RSAUtil.js"
// RSA 测试
{
  let content = "123456"

  // 生成密钥对
  // let keyPair = RSAUtil.getRSAKeyPair();

  let keyPair = {};
  keyPair.publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCRDSXNiPegqx87C4t+g/kzeORxDKQHn0sFOpYoytI5+IRz0/bYwPJ4vK0Yfs5yB5Ws6ekpNyNHs4ePzfEy2dlN3KDMtuyFfUsDxX6lBk4llsMNJESK3EmgKKIHJPUo5/NPoTALQAB9qLH+yLmX68vFStDBX7Vw29hRFJJfFJKbEwIDAQAB"
  keyPair.privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJENJc2I96CrHzsLi36D+TN45HEMpAefSwU6lijK0jn4hHPT9tjA8ni8rRh+znIHlazp6Sk3I0ezh4/N8TLZ2U3coMy27IV9SwPFfqUGTiWWww0kRIrcSaAoogck9Sjn80+hMAtAAH2osf7IuZfry8VK0MFftXDb2FEUkl8UkpsTAgMBAAECgYAgg1Pv6D2pU/IiKApSh356XSTHek/iLYCBYYp7BkttFxmJZP+1wjoXeiNKlFHuGWkhYyUSSfusfL9sKntgLJialWviOyqEF6mGqouDGjtctrNPKmhEbACVKBIBam0dq+NZme8wWAOYZYynsWuAf26GgG4Qz/T/Ru+N14mMMyXBkQJBAOhc6Gg1NNW2Qh4so3hbx1K3iV9ReU+qzpvoQmfMLTLQIPylvd9y6PA+m0lspimWB2SZQf1+S6hx2x4mMM79Xo8CQQCfzoLEyYWGRISE4b+mlIaXIrrF+FoTNSgvOlpA5cihJgOlU/7UuKcjXQacatmokx2pEthCklX2UnnhzMPIJT09AkEApKPP+KZafWLajk7KtSkyniV1rJgqAIziQA3dn3ZIQEzAUsONOZpN+owhs3DMe4LWUi1VWKv4J64kt8QPqVpVeQJATCT/JDsNd1OQfSx/wCTHGJ6AtjHG4Z4TfqVkOcYDWd2eIRmrs7okUXJS4xb6jRtEJ7qF9vp5ITxdPNzvcJ9l1QJAIA9HFKwTg2b1ScKUpJJHptRI+zHXd4MSfCpLUV1fDqETnWnUoZkX2ZszPoPSd7Av4Wh9jx+aZQpq6+uRCcu/cA=="

  let encrypted = RSAUtil.publicKeyEncrypt(content, keyPair.publicKey);
  let dencrypted = RSAUtil.privateKeyDecrypt(encrypted, keyPair.privateKey);
  // console.dir("密钥对：" +
  //   "\n\t" + "公钥：" + keyPair.publicKey +
  //   "\n\t" + "私钥：" + keyPair.privateKey
  // )
  console.log("加密之后的密文(经 BASE64 处理)：" + encrypted)
  console.log("解密之后的明文：" + dencrypted.toString('utf8') +
    "\n" + "原始明文：" + content +
    "\n" + "测试是否通过：" + ( dencrypted.toString('utf8') === content )
  )
}
